from selenium import webdriver
import time


class TestCase:
    def __init__(self):
        self.drvier = webdriver.Chrome()
        self.drvier.get('https://www.itsource.cn')
        time.sleep(1)

    def scroll1(self):
        js1 = 'window.scrollTo(0,1000)'
        self.drvier.execute_script(js1)
        time.sleep(1)

        js2 = 'window.scrollTo(0,document.body.scrollHeight)'
        self.drvier.execute_script(js2)
        time.sleep(2)
        js3 = 'window.scrollTo({top:0,left:0,behavior:"smooth"})'
        self.drvier.execute_script(js3)

    def scroll2(self):
        div_element = self.drvier.find_element_by_xpath('//div[text()="源码动态"]')
        self.drvier.execute_script('arguments[0].scrollIntoView()', div_element)
        time.sleep(1)
    def quit(self):
        time.sleep(5)
        self.drvier.quit()

if __name__ == '__main__':
    case = TestCase()
    # case.scroll1()
    case.scroll2()

    case.quit()

